package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.AttendPunchDailyReportExample.E_ATTEND_PLAN_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_ATTEND_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_COMPANY_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_COMPANY_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_DAILY;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_DAILY_SUMMARY_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_DEPT_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_DEPT_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_EARLIEST_TIME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_EMP_INFO_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_EMP_INFO_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_GO_OUT_HOURS_END;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_GO_OUT_HOURS_START;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_GO_OUT_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_HIS_ATTEND_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_IS_GO_OUT;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_IS_USED;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_LATEST_TIME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_MINUTES;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_MONTHLY;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_OVERTIME_HOURS_END;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_OVERTIME_HOURS_START;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_OVERTIME_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_PUNCH_COUNTS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_SIGN_IN_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_SIGN_OUT_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_WORK_TIME_MINUTE;
import static org.jsola.hr.example.AttendPunchDailyReportExample.E_YEARLY;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_ATTEND_PLAN_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_ATTEND_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_COMPANY_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_COMPANY_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_DAILY;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_DAILY_SUMMARY_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_DEPT_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_DEPT_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_EARLIEST_TIME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_EMP_INFO_ID;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_EMP_INFO_NAME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_GO_OUT_HOURS_END;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_GO_OUT_HOURS_START;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_GO_OUT_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_HIS_ATTEND_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_IS_GO_OUT;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_IS_USED;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_LATEST_TIME;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_MINUTES;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_MONTHLY;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_OVERTIME_HOURS_END;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_OVERTIME_HOURS_START;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_OVERTIME_STATUS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_PUNCH_COUNTS;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_SIGN_IN_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_SIGN_OUT_LOCATION;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_WORK_TIME_MINUTE;
import static org.jsola.hr.example.AttendPunchDailyReportExample.N_YEARLY;

/**
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AttendPunchDailyReportQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_DAILY_SUMMARY_ID, example = E_DAILY_SUMMARY_ID)
    @Length(max = 32)
    private String dailySummaryId;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_COMPANY_NAME, example = E_COMPANY_NAME)
    @Length(max = 100)
    private String companyName;

    @ApiParam(value = N_DEPT_ID, example = E_DEPT_ID)
    @Length(max = 32)
    private String deptId;

    @ApiParam(value = N_DEPT_NAME, example = E_DEPT_NAME)
    @Length(max = 100)
    private String deptName;

    @ApiParam(value = N_ATTEND_PLAN_ID, example = E_ATTEND_PLAN_ID)
    @Length(max = 32)
    private String attendPlanId;

    @ApiParam(value = N_EMP_INFO_ID, example = E_EMP_INFO_ID)
    @Length(max = 32)
    private String empInfoId;

    @ApiParam(value = N_EMP_INFO_NAME, example = E_EMP_INFO_NAME)
    @Length(max = 50)
    private String empInfoName;

    @ApiParam(value = N_YEARLY, example = E_YEARLY)
    @Length(max = 10)
    private String yearly;

    @ApiParam(value = N_MONTHLY, example = E_MONTHLY)
    @Length(max = 10)
    private String monthly;

    @ApiParam(value = N_DAILY, example = E_DAILY)
    @Length(max = 10)
    private String daily;

    @ApiParam(value = N_SIGN_IN_LOCATION, example = E_SIGN_IN_LOCATION)
    @Length(max = 255)
    private String signInLocation;

    @ApiParam(value = N_SIGN_OUT_LOCATION, example = E_SIGN_OUT_LOCATION)
    @Length(max = 255)
    private String signOutLocation;

    @ApiParam(value = N_IS_GO_OUT, example = E_IS_GO_OUT)
    private Integer isGoOut;

    @ApiParam(value = N_GO_OUT_LOCATION, example = E_GO_OUT_LOCATION)
    @Length(max = 255)
    private String goOutLocation;

    /**
     * 外出时长(小时)查询范围
     */
    @ApiParam(value = N_GO_OUT_HOURS_START, example = E_GO_OUT_HOURS_START)
    private BigDecimal goOutHoursStart;
    @ApiParam(value = N_GO_OUT_HOURS_END, example = E_GO_OUT_HOURS_END)
    private BigDecimal goOutHoursEnd;


    @ApiParam(value = N_IS_USED, example = E_IS_USED)
    private Integer isUsed;

    @ApiParam(value = N_ATTEND_STATUS, example = E_ATTEND_STATUS)
    private Integer attendStatus;

    /**
     * 加班时长(小时)查询范围
     */
    @ApiParam(value = N_OVERTIME_HOURS_START, example = E_OVERTIME_HOURS_START)
    private BigDecimal overtimeHoursStart;
    @ApiParam(value = N_OVERTIME_HOURS_END, example = E_OVERTIME_HOURS_END)
    private BigDecimal overtimeHoursEnd;


    @ApiParam(value = N_EARLIEST_TIME, example = E_EARLIEST_TIME)
    @Length(max = 10)
    private String earliestTime;

    @ApiParam(value = N_LATEST_TIME, example = E_LATEST_TIME)
    @Length(max = 10)
    private String latestTime;

    @ApiParam(value = N_PUNCH_COUNTS, example = E_PUNCH_COUNTS)
    private Integer punchCounts;

    @ApiParam(value = N_WORK_TIME_MINUTE, example = E_WORK_TIME_MINUTE)
    private Integer workTimeMinute;

    @ApiParam(value = N_HIS_ATTEND_STATUS, example = E_HIS_ATTEND_STATUS)
    private Integer hisAttendStatus;

    @ApiParam(value = N_OVERTIME_STATUS, example = E_OVERTIME_STATUS)
    private Integer overtimeStatus;

    @ApiParam(value = N_MINUTES, example = E_MINUTES)
    private Integer minutes;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public AttendPunchDailyReportQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

